//
//  StatusCellTopView.swift
//  JJWeibo
//
//  Created by JJ on 15/9/6.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit
import SDWebImage

let JJStatusIconWidth:CGFloat=35
let JJStatusCellMargin:CGFloat=12

class StatusCellTopView: UIView {
    
    var statusViewModel: StatusViewModel? {
        didSet {
            iconView.sd_setImageWithURL(statusViewModel?.userIconUrl)
            nameLabel.text=statusViewModel?.status.user?.name
            memberView.image=statusViewModel?.userMemerImage
            vipVIew.image=statusViewModel?.userVipImage
            
            let str=statusViewModel?.status.created_at ?? ""
            timeLable.text=NSDate.sinaDate(str)?.dateDescription
            sourceLable.text=statusViewModel?.status.source
           
           
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memberView)
        addSubview(timeLable)
        addSubview(sourceLable)
        addSubview(vipVIew)
        let offset=CGPoint(x: JJStatusCellMargin, y: 0)
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: JJStatusIconWidth, height: JJStatusIconWidth), offset: CGPoint(x: JJStatusCellMargin, y: JJStatusCellMargin))
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: offset)
        memberView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLabel, size: nil, offset: offset)
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: offset)
        sourceLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLable, size: nil, offset: offset)
        vipVIew.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
        
        
    }
    
    private lazy var iconView:UIImageView=UIImageView(image: UIImage(named: "avatar_default_big"))
    
    private lazy var nameLabel: UILabel = UILabel(title: "姓名", color: UIColor.darkGrayColor(), fontsize: 14)
    private lazy var memberView:UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    private lazy var timeLable:UILabel=UILabel(title: "刚刚", color: UIColor.orangeColor(), fontsize: 10)
    private lazy var sourceLable:UILabel=UILabel(title: "来自 新浪微博", color: UIColor.darkGrayColor(), fontsize: 10)
    private lazy var vipVIew:UIImageView=UIImageView(image: UIImage(named: "avatar_grassroot"))
}
